Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Openplantbook integration #42359

Closed
wants to merge 14 commits into from
Closed

Conversation

Olen
Copy link
Contributor

@Olen Olen commented Oct 25, 2020

Proposed change

This PR adds access to the OpenPlantbook API, and is mostly a preparation for a later PR to the Plant component.
The Openplantbook component itself does not do much, except providing a way for Home Assistant to communicate with the OpenPlantbook API and online DB to fetch data.
There are two service calls which allows you to search for plant species, and get data for a specific species.
https://open.plantbook.io/

This PR is a replacement for PR#42200 where the git history was problematic after a bad rebase.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

The component requires the user to get a client id and secret to the OpenPlantbook API. It is configured using a config flow.
The Openplantbook API is the exposed to HA as a class where other components (e.g. the Plant component) can fetch data.
A PR for the Plant component where it can take advantage of the OpenPlantbook API will be submitted once this component is accepted.

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@project-bot project-bot bot added this to Needs review in Dev Oct 25, 2020
@Olen Olen changed the title Openplantbook new New integration Openplantbook (2. attempt) Oct 25, 2020
@springstan springstan changed the title New integration Openplantbook (2. attempt) Add Openplantbook integration Oct 25, 2020
@Olen
Copy link
Contributor Author

Olen commented Oct 26, 2020

I still don't understand what I can do to fix the codecov/patch issue.

@RobBie1221
Copy link
Contributor

I still don't understand what I can do to fix the codecov/patch issue.

You can check which lines of codes are not hit by tests:
pytest --cov=homeassistant/components/openplantbook/ --cov-report term-missing -- tests/components/openplantbook/test_*.py

@RobBie1221
Copy link
Contributor

You need 100% coverage for at least config flow.

@Olen
Copy link
Contributor Author

Olen commented Oct 27, 2020

Thanks!

Now I have 100% covreage of config_flow, and all 3 tests succeeds locally.

@PeteBa PeteBa mentioned this pull request Oct 28, 2020
21 tasks
@cgarwood cgarwood added this to Incoming in New Integrations via automation Nov 25, 2020

from .const import ATTR_ALIAS, ATTR_API, ATTR_HOURS, ATTR_SPECIES, CACHE_TIME, DOMAIN

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is configured via config_flow, the CONFIG_SCHEMA shouldn't be needed.

species,
)
wait = 0
while "pid" not in hass.data[DOMAIN][ATTR_SPECIES][species]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncio.Event would be a good replacement for this retry loop.

_LOGGER.debug("Unable to connect to OpenPlantbook: %s", ex)
raise

return {"title": "Openplantbook API"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: There are three different capitalizations of OpenPlantBook in this file. Should they all be replaced with one, correct branding?

return self.async_create_entry(title=info["title"], data=user_input)
except Exception as ex:
_LOGGER.error("Unable to connect to OpenPlantbook: %s", ex)
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception while validating input/trying to connect would typically be given back to the user by showing the form again with the the errors field set. This lets the user fix their input and try again. I'm not sure what the user experience of a thrown exception during config flow would be.

@@ -0,0 +1,13 @@
search:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clear_cache service isn't listed here


async def test_form(hass):
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component doesn't interact with persistent_notification. Does it need to be initialized in the tests?

entity_id = async_generate_entity_id(
f"{DOMAIN}" + ".{}", plant_data["pid"], current_ids={}
)
hass.states.async_set(entity_id, plant_data["display_pid"], attrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with anything in the plant area so take this comment with a grain of salt, but it feels unusual that services are creating and destroying entities. In the light/switch/sensor/etc world it'd be more traditional for the config_entry to know about what entities will be created and for them all to be created during setup.

hass.data[DOMAIN] = {}
if ATTR_API not in hass.data[DOMAIN]:
hass.data[DOMAIN][ATTR_API] = OpenPlantBookApi(
entry.data.get("client_id"), entry.data.get("secret")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout the component there are magic strings that are used in multiple places. It is very common in HA for these all to be defined as constants so there is less chance for mismatching typos. There are already a bunch of these in const.py but there are many that are not.

@github-actions
Copy link

github-actions bot commented Apr 5, 2021

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added stale and removed stale labels Apr 5, 2021
@dgomes
Copy link
Contributor

dgomes commented May 8, 2021

@Olen would you address @joncar comments ? I would like to see this being accepted 馃槃

Dev automation moved this from Needs review to Review in progress May 8, 2021
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has been running stale since 5 Jan, without a response. I think it is fair to say this is really stale and should be closed.

Looking at the PR: It doesn't provide any entities, yet it directly injects/modifies data in the state engine by injecting "fake" entities and data. This is absolutely a no-go.

New Integrations automation moved this from Incoming to Awaiting Requested Changes May 8, 2021
@balloob
Copy link
Member

balloob commented May 9, 2021

This contribution doesn't fit the Home Assistant model. We represent states, not encyclopedia data.

@balloob balloob closed this May 9, 2021
Dev automation moved this from Review in progress to Cancelled May 9, 2021
New Integrations automation moved this from Awaiting Requested Changes to Cancelled May 9, 2021
@dgomes
Copy link
Contributor

dgomes commented May 9, 2021

I agree that information from openplantbook should not become part of the state of the entities, but there is a lot of value in configuring the plant entity with information from openplantbook.

Currently the plant entity yaml exposes all these parameters retrieved from openplantbook as yaml configuration parameters, doesn't it make sense to fill those in automatically? This PR might not have been the best approach, but doesn't the use case make sense ?

@balloob
Copy link
Member

balloob commented May 10, 2021

A config flow step could fetch this information when configuring a plant.

@Olen
Copy link
Contributor Author

Olen commented May 10, 2021

A config flow step could fetch this information when configuring a plant.

We tried that approach first, however we needed to add a few more data points to the plant object, and that was rejected since you do not allow "config" in the attributes of an entity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dev
  
Cancelled
New Integrations
  
Cancelled
Development

Successfully merging this pull request may close these issues.

None yet

8 participants